package org.dromara.system.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.system.domain.vo.TUserWalletFlowVo;
import org.dromara.system.domain.bo.TUserWalletFlowBo;
import org.dromara.system.service.ITUserWalletFlowService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 用户钱包流水
 *
 * @author Miles Meng
 * @date 2025-08-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/userWalletFlow")
public class TUserWalletFlowController extends BaseController {

    private final ITUserWalletFlowService tUserWalletFlowService;

    /**
     * 查询用户钱包流水列表
     */
    @SaCheckPermission("system:userWalletFlow:list")
    @GetMapping("/list")
    public TableDataInfo<TUserWalletFlowVo> list(TUserWalletFlowBo bo, PageQuery pageQuery) {
        return tUserWalletFlowService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出用户钱包流水列表
     */
    @SaCheckPermission("system:userWalletFlow:export")
    @Log(title = "用户钱包流水", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TUserWalletFlowBo bo, HttpServletResponse response) {
        List<TUserWalletFlowVo> list = tUserWalletFlowService.queryList(bo);
        ExcelUtil.exportExcel(list, "用户钱包流水", TUserWalletFlowVo.class, response);
    }

    /**
     * 获取用户钱包流水详细信息
     *
     * @param walletFlowId 主键
     */
    @SaCheckPermission("system:userWalletFlow:query")
    @GetMapping("/{walletFlowId}")
    public R<TUserWalletFlowVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long walletFlowId) {
        return R.ok(tUserWalletFlowService.queryById(walletFlowId));
    }

    /**
     * 新增用户钱包流水
     */
    @SaCheckPermission("system:userWalletFlow:add")
    @Log(title = "用户钱包流水", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TUserWalletFlowBo bo) {
        return toAjax(tUserWalletFlowService.insertByBo(bo));
    }

    /**
     * 修改用户钱包流水
     */
    @SaCheckPermission("system:userWalletFlow:edit")
    @Log(title = "用户钱包流水", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TUserWalletFlowBo bo) {
        return toAjax(tUserWalletFlowService.updateByBo(bo));
    }

    /**
     * 删除用户钱包流水
     *
     * @param walletFlowIds 主键串
     */
    @SaCheckPermission("system:userWalletFlow:remove")
    @Log(title = "用户钱包流水", businessType = BusinessType.DELETE)
    @DeleteMapping("/{walletFlowIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] walletFlowIds) {
        return toAjax(tUserWalletFlowService.deleteWithValidByIds(List.of(walletFlowIds), true));
    }
}
